package com.museum.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.museum.entity.DO.AreaPermission;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Ruiwen
 * @since 2020-12-19
 */
@Repository
public interface AreaPermissionMapper extends BaseMapper<AreaPermission> {
    @Select("select permission_id from area_permission where area_number = #{number} and status = 0")
    List<Integer> selectPermissionIds(Integer number);
    @Select("select permission_id from area_permission where area_number = #{areaNumber} and status=0")
    List<Integer> getUserAreaPermissionByNumber(Integer areaNumber);

    /**
     * 根据地域编号查询不可用权限
     * @param areaNumber
     * @return
     */
    @Select("SELECT permission_id FROM area_permission WHERE area_number=#{areaNumber}  AND `status`=1 ")
    List<Integer> getNoUsePermissionIDs(Integer areaNumber);
    /**
     * 根据地域编号查询不可用权限
     * @param areaNumber
     * @return
     */
    @Select("SELECT permission_id FROM area_permission WHERE area_number=#{areaNumber}  AND `status`=0 ")
    List<Integer> getCanUsePermissionIDs(Integer areaNumber);

    /**
     * 打开菜单权限
     * @param permissionID
     * @param areaNumber
     * @return
     */
    @Update("update area_permission set `status` =0 where permission_id=#{permissionID} AND area_number=#{areaNumber}")
    int openPermissionByPermissionID(Integer permissionID,Integer areaNumber);


    /**
     * 关闭菜单权限
     * @param permissionID
     * @param areaNumber
     * @return
     */
    @Update("update area_permission set `status` =1 where permission_id=#{permissionID} AND area_number=#{areaNumber}")
    int closePermissionByPermissionID(Integer permissionID,Integer areaNumber);

    @Select("select permission_id from area_permission WHERE area_number =#{areaNumber} ")
    List<Integer> getAllPermissionIds(Integer areaNumber);

}
